package com.xpgk.mvc.statistic.scost;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Record;
import com.xpgk.constant.ConstantSplitPage;
import com.xpgk.dto.SplitPage;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.statistic.monthNursing.MonthNursingStatisticSQL;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolDateTime;

public class ScostController  extends  BaseController{
	
		private  ScostStatisticService  scostStatisticService;
	
		public  void  index()
		{	
			Organization  org=Organization.dao.findById(getCUserOrganIds());
			setAttr("organization", org);
			setAttr("startTime", ToolDateTime.getMonthOneDay(new Date()));
			render("scost.html");
		}
		/**获取费用支出记录
		 * 
		 */
		public  void  getCostInfo()
		{
			String json = paging(splitPage, ScostSQL.sqlId_splitPageSelect, ScostSQL.sqlId_splitPageFrom);
			renderJson(json);
		}
		
		
		public  void  excel()
		{	
			SplitPage  splitPage=new SplitPage();
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("startTime", getPara("startTime"));
			param.put("endTime", getPara("endTime"));
			param.put("organIds", getPara("organIds"));
			param.put("zcType", getPara("fyzc_select").equals("-1")?"":getPara("fyzc_select"));
			param.put("zffs", getPara("skfs_select").equals("-1")?"": getPara("skfs_select"));
			param.put("zcUser", getPara("zcry_select").equals("-1")?"":getPara("zcry_select"));
			splitPage.setPageSize(ConstantSplitPage.default_maxSize);
			splitPage.setQueryParam(param);
			String json = paging(splitPage, ScostSQL.sqlId_splitPageSelect, ScostSQL.sqlId_splitPageFrom);
			List<Record>  list=(List<Record>)splitPage.getList();
			
			//将搜索条件加入表格
//			Record  record=new Record();
			//机构  
			Organization  organ=Organization.dao.findById(param.get("organIds"));
			//支出类别
			Code  zcTypecode=Code.dao.findById(getPara("fyzc_select"));
			//支出方式
			Code  zffscode=Code.dao.findById(getPara("skfs_select"));
			//支出人员
			User  zcuser=User.dao.findById(getPara("zcry_select"));
			String  zctypestr=zcTypecode==null?"":(",支出类别："+zcTypecode.getStr(Code.column_name));
			String  zffsstr=zffscode==null?"":(",支出方式："+zffscode.getStr(Code.column_name));
			String  zcuserstr=zcuser==null?"":(",支出人员："+zcuser.getStr(User.column_name));
			String  search="支出时间："+param.get("startTime")+"~"+param.get("endTime")+",门店："+organ.getStr(Organization.column_name)+
					zctypestr+zffsstr+zcuserstr+",导出人员："+getCUser().getStr(User.column_name);
			
			render(new ScostStatisticXLS(list,search,"费用支出"));
		}
}
